package com.hongkuncheng.cms.model;

import javax.persistence.*;
import java.util.List;
import java.util.Objects;
import java.io.Serializable;

@Entity
public class Datamodel implements Serializable {
    protected int id;
    protected String name;
    private List<Columns> columnses;
    protected List<Dataitem> dataitems;
    protected DatamodelType datamodelType;
    protected List<Department> departments;
    protected List<Homepage> homepages;
    protected List<Zhuanti> zhuantis;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Basic
    @Column(name = "name", nullable = false, length = 255)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Datamodel datamodel = (Datamodel) o;
        return id == datamodel.id &&
                Objects.equals(name, datamodel.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name);
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "datamodel")
    public List<Columns> getColumnses() {
        return columnses;
    }

    public void setColumnses(List<Columns> columnses) {
        this.columnses = columnses;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "datamodel")
    public List<Dataitem> getDataitems() {
        return dataitems;
    }

    public void setDataitems(List<Dataitem> dataitems) {
        this.dataitems = dataitems;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "type_id", referencedColumnName = "id", nullable = false)
    public DatamodelType getDatamodelType() {
        return datamodelType;
    }

    public void setDatamodelType(DatamodelType datamodelType) {
        this.datamodelType = datamodelType;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "datamodel")
    public List<Department> getDepartments() {
        return departments;
    }

    public void setDepartments(List<Department> departments) {
        this.departments = departments;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "datamodel")
    public List<Homepage> getHomepages() {
        return homepages;
    }

    public void setHomepages(List<Homepage> homepages) {
        this.homepages = homepages;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "datamodel")
    public List<Zhuanti> getZhuantis() {
        return zhuantis;
    }

    public void setZhuantis(List<Zhuanti> zhuantis) {
        this.zhuantis = zhuantis;
    }
}
